package com.fengshang.wedding.mvc.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.fengshang.wedding.domain.model.internal.UserEntity;
import com.fengshang.wedding.domain.service.api.IUserManager;

public class LoginController extends SimpleFormController {
    
	private IUserManager userManager;
	
	public IUserManager getUserManager() {
		return userManager;
	}


	public void setUserManager(IUserManager userManager) {
		this.userManager = userManager;
	}


	@SuppressWarnings("unchecked")
	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		
		System.out.println(command);
		UserEntity user = (UserEntity) command;
		Map<String, UserEntity> modle = errors.getModel();
		modle.put("user", user);
		userManager.saveUser(user);
		return new ModelAndView(getSuccessView(), modle);
	}

}
